package com.ld.security.server.admin.modules.ge.vo;

import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.base.vo.ProxyVo;
import com.ld.security.server.admin.modules.ge.entity.GeCompEntity;
import com.ld.security.server.admin.modules.ge.entity.GeCompTelEntity;
import com.ld.security.common.core.base.SuperVo;
import com.ld.security.common.mybatis.anno.QueryKey;
import com.ld.security.common.mybatis.base.vo.NodeVo;
import com.ld.security.common.mybatis.constant.SqlCondition;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class CompTreeVo implements SuperVo,ProxyVo {

    private String id="-1";


    @SqlKey(name = "id",valueField = "id",value = SqlCondition.ne)
    //故意查询所有
    @QueryKey
    private List<GeCompTelEntity> telList;



    @SqlKey(name = "telId",valueField = "telList.id",value = SqlCondition.in)
    @QueryKey(groupKey = "compType")
    private Map<String,List<GeCompEntity>> compMap;


    private List<NodeVo> compTree;

    @Override
    public void queryAfter() {



        NodeVo pp =new NodeVo();

        for (GeCompTelEntity telEntity : telList) {
            NodeVo c = pp.addChildren(telEntity.getLabel(),telEntity.getId());
            List<GeCompEntity> list =  compMap.get(telEntity.getId());
            if(list == null){
                continue;
            }
            for (GeCompEntity geCompEntity : list) {
                c.addChildren(geCompEntity.getLabel(),geCompEntity.getId());
            }
        }
        this.compTree = pp.getChildren();
    }
}
